from django.shortcuts import render
from rest_framework.views import APIView
from rest_framework.viewsets import ModelViewSet
from faker import Faker
# from utils.response import ResponsePackaging

# Create your views here.
from utils.response import SuccessResponse


class IdCard(APIView):
    def post(self, request, *args, **kwargs):
        """
        生成身份证
        """
        fake = Faker(locale='zh_CN')
        data = request.data
        min = data.get('minage')
        max = data.get('maxage')
        num = data.get('num')
        sex = data.get('sex')
        list = []
        if num != 1:
            for i in range(1, int(num)):
                list.append(fake.ssn(int(min), int(max), sex)+"   ")
        list.append(fake.ssn(int(min), int(max), sex))
        return SuccessResponse(data={'data': list}, msg='生成成功！')
        # return Response(200, list, '生成成功！')


class PhoneApiView(APIView):
    """
    手机号生成
    """
    def post(self, request, *args, **kwargs):
        fake = Faker(locale='zh_CN')
        data = request.data
        num = data.get('num')
        list = []
        if num != 1:
            for i in range(1, int(num)):
                list.append(fake.phone_number()+"   ")
        list.append(fake.phone_number())
        return SuccessResponse(data={'data': list}, msg='生成成功！')


class CreditApiView(APIView):
    """
    信用卡号生成
    """
    def post(self, request, *args, **kwargs):
        fake = Faker(locale='zh_CN')
        data = request.data
        num = data.get('num')
        list = []
        if num != 1:
            for i in range(1, int(num)):
                list.append(fake.credit_card_number()+"   ")
        list.append(fake.credit_card_number())
        return SuccessResponse(data={'data': list}, msg='生成成功！')
